# _*_ encoding:utf-8 _*_
from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from datetime import datetime


class UserRecord(models.Model):

    win_los = (("los", u"输"), ("win", u"赢"),("los_win",u"等待开奖结果"))
    smabig = (("small", u"开奖结果:小"), ("big", u"开奖结果;大"))
    state = (("waiting", u"等待开奖"), ("over", "已开奖"))

    token = models.CharField(max_length=100)
    small_big = models.CharField(max_length=100,choices=smabig,verbose_name='选中结果',blank=False,null=False)
    iswining = models.CharField(max_length=100, choices=win_los, default="los_win",verbose_name="输赢")
    status = models.CharField(max_length=100, choices=state, default="waiting", verbose_name="开奖状态")
    count = models.IntegerField(verbose_name="资产",default=0)
    beton = models.IntegerField(verbose_name="赌注",default=0)
    payoff = models.IntegerField(verbose_name="收益",default=0)
    platrecord = models.ForeignKey(to='PlatformRecord',on_delete=models.CASCADE)
    add_time = models.DateTimeField("添加时间", default=datetime.now)


    def __str__(self):
        return '%s-%s-%s-%s' % (self.get_status_display(),self.platrecord.nper,self.get_small_big_display(),self.get_iswining_display())

    class Meta:
        verbose_name_plural = "用户信息"


class PlatformRecord(models.Model):

    uesrrecord = GenericRelation("UserRecord")
    smabig = (("small", u"开奖结果:小"), ("big", u"开奖结果:大"))

    nper = models.CharField(max_length=100, verbose_name="期数")
    num = models.IntegerField(verbose_name="开奖数字")
    isbigs = models.CharField(max_length=100,choices=smabig,default='small',verbose_name="大小结果")
    add_time = models.DateTimeField("添加时间", default=datetime.now)

    def __str__(self):
        return '%s-%s-%s' % (self.nper, self.num,self.get_isbigs_display())

    class Meta:

        verbose_name_plural = "平台信息"



